package webreg.model.container;

import java.util.Iterator;
import java.util.TreeSet;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import webreg.model.Disciplin;


/** This class wraps multiple 
 * disciplins in one container class for persistence.
 * 
 * @author STKNOLL
 */
@XmlRootElement(name = "disciplinContainer")
public class DisciplinContainer {

	/** Set containing the disciplin */
	private TreeSet<Disciplin> mDisciplins;

	/** Constructor of a disciplin container */
	public DisciplinContainer() {
		mDisciplins = new TreeSet<Disciplin>(new DisciplinComparator());
	}
	
	/** Constructor of a disciplin container
	 * 
	 * @param disciplins The disciplins to store.
	 */
	public DisciplinContainer(TreeSet<Disciplin> disciplins) {
		mDisciplins = disciplins;
	}
	
	/** Copy constructor for disciplin container
	 * 
	 * Private copy constructor for a disciplin container
	 * 
	 * @param toCopy The disciplin container to copy
	 */
	public DisciplinContainer (DisciplinContainer toCopy) {
		this(toCopy.mDisciplins);
	}
	
	/** Implementation of the equals method.
	 * 
	 * @param toCompare The disciplin container to compare with
	 * @return True, if disciplin matches
	 */
	public boolean equals(DisciplinContainer toCompare) {
		Iterator<Disciplin> iter = this.mDisciplins.iterator();
		Iterator<Disciplin> iter2 = toCompare.mDisciplins.iterator();
		for (; iter.hasNext() && iter2.hasNext(); ) {
			Disciplin disciplin1 = (Disciplin)iter.next();
			Disciplin disciplin2 = (Disciplin)iter2.next();
			if (disciplin1.equals(disciplin2) == false) return false;
		}
		return true;
	}

		
	/** Sets the disciplins that are stored in the container
	 * 
	 * @param disciplins The disciplins to hold in the container
	 */
	public void setDisciplins(TreeSet<Disciplin> disciplins) {
		mDisciplins = disciplins;
	}

	/** Gets the stored disciplins of the container
	 * 
	 * @return The disciplins stored in the container.
	 */
	@XmlElement(name = "Disciplin")	
	public TreeSet<Disciplin> getDisciplins() {
		return mDisciplins;
	}

}
